package com.lianrui.web;

import java.util.Locale;
import java.util.Map;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;

public class MyViewResover implements ViewResolver {
	private Map<String, ViewResolver> resolvers;

	@Override
	public View resolveViewName(String viewName, Locale locale) throws Exception {
//		viewName = StringUtils.defaultIfEmpty(viewName, "login");
		int n = viewName.lastIndexOf(".");
		String suffix = "";
		
		//默认为JSP页面
		if (n == (-1)) {
			suffix = "jsp";
		} else {
			suffix = viewName.substring(n + 1);
			viewName = viewName.substring(0, n);
		}

		ViewResolver resolver = resolvers.get(suffix);

		if (resolver != null) {
			return resolver.resolveViewName(viewName, locale);
		} else {
			return null;
		}
	}

	public Map<String, ViewResolver> getResolvers() {
		return resolvers;
	}

	public void setResolvers(Map<String, ViewResolver> resolvers) {
		this.resolvers = resolvers;
	}

}
